package com.shop.cloud.common.email.config;

import io.github.biezhi.ome.OhMyEmail;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 邮箱配置初始化
 *
 * @author
 */
@Slf4j
@Configuration
public class EmailConfiguration {

    private final EmailConfigProperties emailConfigProperties;

    public EmailConfiguration(EmailConfigProperties emailConfigProperties) {
        this.emailConfigProperties = emailConfigProperties;
    }

    /**
     * 邮箱配置初始化
     */
    @PostConstruct
    public void init() {
        String mailHost = emailConfigProperties.getMailSmtpHost();
        String mailUsername = emailConfigProperties.getMailSmtpUsername();
        String mailPassowrd = emailConfigProperties.getMailSmtpPassword();
        log.info("mailHost:{},mailUsername:{},mailPassowrd:{}", mailHost,mailUsername,mailPassowrd);
        final Properties properties = OhMyEmail.defaultConfig(false);
        properties.setProperty("mail.smtp.host", mailHost);
        OhMyEmail.config(properties, mailUsername, mailPassowrd);
    }
}
